<?php
/**
 * Formulário padrão
 */
class App_Form_Fornecedor extends Voitech_Form
{
	public function __construct($options=array())
	{
		parent::__construct($options);
		
		$this->setAttribs(array('name'=>'frmCadastroFornecedor', 'id'=>'frmCadastroFornecedor', 'class'=>'form last-child'));
		
		// add id element
                $this->addElement('hidden', 'co_fornecedor');

                // remove id's decorators
                $this->getElement('co_fornecedor')
                    ->removeDecorator('DtDdWrapper')
                    ->removeDecorator('HtmlTag')
                    ->removeDecorator('Label');
		
		$noFornecedor 	= new Zend_Form_Element_Text( 'no_fornecedor' );
		$noFornecedor->setLabel( 'Fornecedor:' )
				 ->setAttribs( array('size'=>'55') )
		         ->addFilter( new Zend_Filter_StringTrim() )
				 ->addValidator( new Zend_Validate_StringLength( array( 'min'=>'4', 'max'=>'155' ) ) )
		         ->setDecorators( $this->_decoratorDefault )
				 ->setRequired( true );
		$this->addElement( $noFornecedor );	
		
		$nuCnpj = new Zend_Form_Element_Text( 'nu_cnpj' );
		$nuCnpj->setLabel( 'CNPJ:' )
			   ->setAttribs( array( 'size'=>'15', 'maxlength'=>'14' ) )
			   ->addFilter( new Zend_Filter_StringTrim() )
			   ->addFilter( new Zend_Filter_Alnum() )
			   ->addValidator( new Zend_Validate_StringLength( array( 'min'=>'14', 'max'=>'14' ) ) )
			   //->addValidator( new Voitech_Validate_Cnpj() )
			   ->addValidator( new Zend_Validate_Alnum() )
			   ->setDecorators( $this->_decoratorDefault )
			   ->setRequired( true );
		$this->addElement( $nuCnpj );
		
		$nuInscricao = new Zend_Form_Element_Text( 'nu_inscricao' );
		$nuInscricao->setLabel( 'Inscrição Municipal:' )
		            ->setAttribs( array( 'size'=>'15', 'maxlength'=>'20' ) )
		            ->addFilter( new Zend_Filter_StringTrim() )
		            ->addFilter( new Zend_Filter_Alnum() )
		            ->addValidator( new Zend_Validate_Alnum() )
		            ->addValidator( new Zend_Validate_StringLength( array( 'max'=>'20' ) ) )
		            ->setDecorators( $this->_decoratorDefault )
		            ->setRequired( false );		
		$this->addElement( $nuInscricao );
                
                $dsEndereco = new Zend_Form_Element_Text( 'ds_endereco' );
		$dsEndereco->setLabel( 'Endereço:' )
			   ->setAttribs( array( 'size'=>'60' ) )
			   ->addFilter( new Zend_Filter_StringTrim() )
			   ->addFilter( new Zend_Filter_Alnum() )
			   ->setDecorators( $this->_decoratorDefault );
		$this->addElement( $dsEndereco );
		
		$nuTelefone = new Zend_Form_Element_Text( 'nu_telefone' );
		$nuTelefone->setLabel( 'Telefone:' )
		            ->setAttribs( array( 'size'=>'15', 'maxlength'=>'20' ) )
		            ->addFilter( new Zend_Filter_StringTrim() )
		            ->addFilter( new Zend_Filter_Alnum() )
		            ->setDecorators( $this->_decoratorDefault );		
		$this->addElement( $nuTelefone );
                
                $obPessoaRepositorio = new App_Model_PessoaRepository();
                $selectBox = new Zend_Form_Element_Select( 'co_representante' );
                $selectBox->setLabel('Representante:');
                $selectBox->setAttribs( array('class'=> 'last-child' ) );
                $selectBox->setDecorators( $this->_decoratorDefault );
                $selectBox->addMultiOptions( Voitech_Util::converteModeloArrayCombo($obPessoaRepositorio->listarTodos(array('st_atvio'=>'s'))
                                            , 'CoPessoa', 'NoPessoa')  );
                $selectBox->addFilters( array('StringTrim','StripTags') );
                $this->addElement( $selectBox );
                
                $buttonCancelar = new Zend_Form_Element_Button('Cancelar');
		$buttonCancelar->setAttribs( array('class'=> 'first-child last-child','style'=>'float:left;margin-top: 17px', 'id' => 'btnCancelar' ) )
		           ->removeDecorator( 'label' );
		$this->addElement( $buttonCancelar );

		$buttonCdst = new Zend_Form_Element_Button('Salvar');
		$buttonCdst->setAttribs( array('class'=> 'first-child last-child','style'=>'float:right; margin-top: 17px', 'id' => 'btnSalvar' ) )
		           ->removeDecorator( 'label' );
		
		$this->addElement( $buttonCdst );		
		$this->addDisplayGroup(array('no_fornecedor','nu_cnpj','nu_inscricao','ds_endereco','nu_telefone','co_representante','Cancelar','Salvar'),'Cadastro',array('legend' => 'Formulario de cadastro de fornecedor', 'class'=>'grey-bg first-child last-child fieldset-with-legend fieldset-with-legend-first-child'));
	}
}